#!/bin/sh
if [ $# -ge 2 ]
then
  printf '%s [revision]\n' "$0" >&2
  exit 1
fi
set -e -x
pwd="$PWD"
name=mbank-cli
revision="${1:-tip}"
version=$(hg log -r "$revision" --template='{date|isodate}' | head -c 10 | tr -d -)
sourceroot=$(mktemp -d -t "$name-source-XXXXXX")
export TAR_OPTIONS="--owner root --group root --mode a+rX --format ustar"
export GZIP='-9 -n'
mkdir -p "$sourceroot/$name-$version"
hg archive -r "$revision" "$sourceroot/$name-$version"
cd "$sourceroot"
(
  cd $name-*/doc
  make
)
rm -rf $name-*/private/
rm -rf */.hg*
tar -czf "$pwd/$name-$version.tar.gz" */
rm -rf "$sourceroot"
